﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufToolDefinition.h"
#include "GnufAppearanceSetting.h"
#include "GnufDropdownMenuControl.h"
#include "GnufButtonControl.h"

namespace gnuf {

    class GNUF_BASE_EXPORT DropdownMenuToolDefinition
        : public ToolDefinition
        , public IDropdownMenuControlHandler
        , public IButtonControlHandler
    {
        typedef DropdownMenuControlAdpatation::MenuItemType MenuItemType;
        CANNOT_COPY_OR_ASSIGN(DropdownMenuToolDefinition)
    public:
        static EItemType Type() { return DropdownMenuControl::Type; }
        DropdownMenuToolDefinition(const wchar_t *, gcmp::OwnerPtr<Info> &);
        ~DropdownMenuToolDefinition();

    public:
        inline ButtonControl* dropdownButtonControl() { return m_dropdownButtonControl.get(); }
        inline DropdownMenuControl* dropdownMenuControl() { return m_dropdownMenuControl.get(); }
        void setCustomizeArrowIconPath(const std::wstring&);
        void setCustomizeArrowPathforIndexOfButton(int, const std::wstring&);
        void setCustomizeAppearanceSetting(gcmp::OwnerPtr<ButtonAppearanceSetting>&);
        const std::wstring& customizeArrowIconPath() const { return m_customizeArrowIconPath; }

        void setMenuCaption(const std::wstring&);
        void setButtonInfo(const Info&);
        void setButtonText(const std::wstring&);
        void insertMenuItem(int, const Info&, MenuItemType type = MenuItemType::ePushButton);
        void addMenuItem(const Info&, MenuItemType type = MenuItemType::ePushButton);
        void addMenuGroup();
        void removeMenuItem(int);
        void renameMenuItem(int, const Info&);
        void renameMenuItem(int, const std::wstring&);
        void selectMenuItem(int);
        void setCurrentIndex(int);
        void removeSeparator(int);
        void menuItemCount(int& idx) const;

    protected:
        // Inherits from IDropdownMenuControlHandler...
        virtual void onCurrentIndexChanged(int, Item*) override {}        
        virtual void onCheckStatusChanged(int, bool) override {}

        // Inherits from IButtonControlHandler...
        virtual void onClicked() {};
        virtual void onChecked(bool) {};
        virtual bool onSupportToSelect() const { return false; };

        // Inherits from ToolDefinition
        virtual void onRefreshData(const ToolDefinitionData &) override;

    private:
        gcmp::OwnerPtr<DropdownMenuControl> m_dropdownMenuControl;
        gcmp::OwnerPtr<ButtonControl> m_dropdownButtonControl;
        std::wstring m_customizeArrowIconPath;
    };
}
